﻿
using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Utils;
using Wuqi.Webdiyer;

public partial class WebPage_Index_FankuiYijian : SystemBBasePage
{

    private Maticsoft.Model.Feedback feed = new Maticsoft.Model.Feedback();
    private Maticsoft.BLL.Feedback feedBack = new Maticsoft.BLL.Feedback();
    private int pageIndex = 0;
    protected bool result;
    private string sql = "1=1 ";
    private int text = Convert.ToInt32(PageIndex.pageIndex);
    private int Uid = 0;

    protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
    {
        this.page = e.NewPageIndex + 1;
        this.getFankui(this.text, e.NewPageIndex, this.sql);
    }

    private void getFankui(int pageSum, int index, string where)
    {
        this.Uid = int.Parse(base.GetCookie("admin").ToString());
        StringBuilder builder = new StringBuilder();
        StringBuilder builder2 = new StringBuilder();
        builder.Append("<tr >");
        builder.Append("<th width='200' style='height: 42px'>客户</th>");
        builder.Append("<th width='80' style='height: 42px'>类型</th>");
        builder.Append("<th width='360' style='height: 42px'>内容</th>");
        builder.Append("<th width='80' style='height: 42px'>状态</th>");
        builder.Append("<th width='80' style='height: 42px'>日期</th>");
        builder.Append("<th width='100' style='height: 42px'>操作</th>");
        builder.Append("</tr>");
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        Maticsoft.Model.UserInfo info2 = new Maticsoft.Model.UserInfo();
        int num = 0;
        Pagers pagers = DbHelperSQL.SelectByPager("*", where, "Id desc", index, pageSum, "Feedback", string.Empty, string.Empty);
        List<Maticsoft.Model.Feedback> list = this.feedBack.DataTableToList(pagers.MyData);
        foreach (Maticsoft.Model.Feedback feedback in list)
        {
            if ((num % 2) != 0)
            {
                builder2.Append("<tr>");
            }
            else
            {
                builder2.Append("<tr class='alt'>");
            }
            num++;
            builder2.Append("<td width='200' style='height: 42px'>" + feedback.title + "<br />" + feedback.Contact + "</td>");
            if (feedback.Category == "seller")
            {
                builder2.Append("<td width='80' style='height: 42px'>商务合作</td>");
            }
            if (feedback.Category == "suggest")
            {
                builder2.Append("<td width='80' style='height: 42px'>意见反馈</td>");
            }
            builder2.Append("<td width='360' style='height: 42px'><div style='overflow: hidden; width:360px;'>" + feedback.Content + "</div></td>");
            if (feedback.User_id != 0)
            {
                foreach (Maticsoft.Model.UserInfo info3 in info.GetModelList("Id=" + feedback.User_id))
                {
                    builder2.Append("<td width='80' style='height: 42px'>" + info3.Username + "</td>");
                }
            }
            else
            {
                builder2.Append("<td width='80' style='height: 42px'>&nbsp;</td>");
            }
            builder2.Append("<td width='80' style='height: 42px'>" + feedback.Create_time + "</td>");
            if (feedback.User_id == 0)
            {
                builder2.Append(string.Concat(new object[] { "<td width='100' style='height: 42px'><a class=\"remove-record\" href='Index_FankuiYijian.aspx?del=", feedback.Id, "&pageIndex=", index, "&where=", DESEncrypt.Encrypt(where, "type"), "'>删除</a>|<a href='Index_FankuiYijian.aspx?update=", this.Uid, "&type=", feedback.Id, "'>处理</a></td>" }));
            }
            else
            {
                builder2.Append(string.Concat(new object[] { "<td width='100' style='height: 42px'><a class=\"remove-record\" href='Index_FankuiYijian.aspx?del=", feedback.Id, "&pageIndex=", index, "&where=", DESEncrypt.Encrypt(where, "type"), "'>删除</a></td>" }));
            }
            builder2.Append("</tr>");
        }
        this.Literal1.Text = builder.ToString();
        this.Literal2.Text = builder2.ToString();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "index";
        if ((base.Request.QueryString["update"] != null) && (base.Request.QueryString["type"] != null))
        {
            this.updateFeedBack(Convert.ToInt32(base.Request.QueryString["update"].ToString()), Convert.ToInt32(base.Request.QueryString["type"].ToString()));
            base.SetSuccess("处理成功！");
            base.Response.Redirect("Index_FankuiYijian.aspx");
        }
        if (this.likename.Text != string.Empty)
        {
            this.sql = this.sql + " and Content like '%" + this.likename.Text + "%' ";
        }
        if (this.cate.SelectedIndex > 0)
        {
            this.sql = this.sql + " and Category='" + Helper.GetString(this.cate.SelectedValue, string.Empty) + "' ";
        }
        if (!base.IsPostBack && (base.Request.QueryString["del"] != null))
        {
            this.feedBack.Delete(Convert.ToInt32(base.Request.QueryString["del"].ToString()));
            base.SetSuccess("删除成功！");
            if ((base.Request.QueryString["where"] != null) && (base.Request.QueryString["where"].ToString() != ""))
            {
                this.sql = DESEncrypt.Decrypt(base.Request.QueryString["where"].ToString(), "type");
            }
        }
        this.pageSum(this.sql, this.text);
        this.getFankui(this.text, this.pageIndex, this.sql);
    }

    private void pageSum(string where, int count)
    {
        this.AspNetPager1.PageSize = count;
        this.AspNetPager1.RecordCount = this.feedBack.GetModelList(this.sql).Count;
        if ((base.Request.QueryString["pageIndex"] != null) && (base.Request.QueryString["pageIndex"].ToString() != ""))
        {
            this.AspNetPager1.CurrentPageIndex = Convert.ToInt32(base.Request.QueryString["pageIndex"].ToString());
        }
        this.AspNetPager1.DataBind();
    }

    private void updateFeedBack(int uid, int id)
    {
        this.feedBack.UpdateFeedBackUser(id, uid);
    }

    private int page
    {
        get
        {
            if (this.ViewState["page"] != null)
            {
                return Convert.ToInt32(this.ViewState["page"].ToString());
            }
            return 1;
        }
        set
        {
            this.ViewState["page"] = value;
        }
    }
}


